<?php

namespace app\admin\controller;
use think\Db;

class Exchange extends Common{

	public function exchange(){
		return $this->fetch();
	}

	public function exchangeList(){
		$limit = request()->param('limit')?:20;
		$username   = request()->param('username');
		$uid   = request()->param('uid');
		$where      = '1=1';
		if ($username != '') {
            $where .= ' and u.username like \'%' . $username . '%\'';
        }
        if($uid != '') {
            $where .= ' and t.uid='.$uid;
        }
		$data  = Db::table('tp_exchange_record')
				->alias('e')
				->join('tp_user u','u.id = e.uid','LEFT')
				->join('tp_coin_wallet w1','w1.id = e.wid','LEFT')
				->join('tp_coin_wallet w2','w2.id = e.to_wid','LEFT')
				->whereTime('e.date','>=','2021-05-16 00:00:00')
				->where($where)
				->order('id desc')
				->field('e.*,u.username,w1.name,w2.name to_name')
				->paginate($limit);
		$data = $data->toArray();
		return $this->tableData($data);
	}
}